<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../js/jquery-3.6.0.min.js"></script>
</head>

<body>
    <button>get</button>
    <button>post</button>
    <button>jsonp</button>
</body>
<script>

    console.log($, jQuery, $ === jQuery);
    console.dir($);


    // $.ajax 是函数$的静态方法   ($别名 jQuery)

    jQuery("button").eq(0).click(function () {
        var wd = "";
        var col = "id";
        var type = "asc";
        var page = 1;
        var size = 5;
        $.ajax({
            type: "get",
            url: "http://localhost/2210_php/day30_demo/php/searchOrderLimit.php",
            data: {
                wd, col, type, page, size,
            },
            async: true,
            dataType: "json",
            success: function (res) {
                console.log(res);
            },
            error: function (err) {
                console.log(err);
            }
        })
    })

    jQuery("button").eq(1).click(function () {
        var user = "a123123";
        var pwd = "123123";
        $.ajax({
            type: "post",
            url: "http://localhost/2210_php/day30_demo/php/login.php",
            data: {
                user, pwd
            },
            async: true,
            dataType: "json",
            success: function (res) {
                console.log(res);
            },
            error: function (err) {
                console.log(err);
            }
        })
    })

    jQuery("button").eq(2).click(function () {
        var wd = "";
        var col = "id";
        var type = "asc";
        var page = 1;
        var size = 5;
        $.ajax({
            type: "get",
            url: "http://localhost/2210_php/jsonp/searchOrderLimitCallback.php",
            data: {
                wd, col, type, page, size,
            },
            async: true,
            dataType: "jsonp",  // 表示使用jsonp的形式向接口发送请求
            jsonp: "cb",  // 回调函数的字段名(默认callback)
            jsonpCallback: "hahaha",  // 回调函数名(名字默认随机生成)
            // cb=hahaha

            success: function (res) {
                console.log(res);
            },
            error: function (err) {
                console.log(err);
            }
        })
    })

</script>

</html>